package com.yanqu.road.server.logic.activity.condition.xiuxian;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.task.args.XiuXianXianLiRankArgs;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseNewRankActivityCondition;
import com.yanqu.road.server.manger.activity.xiuxian.XiuXianMgr;
import org.apache.kafka.common.protocol.types.Field;

import java.math.BigInteger;

public class XiuXianXianLiRankCondition extends BaseNewRankActivityCondition {

    public XiuXianXianLiRankCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        XiuXianXianLiRankArgs rankArgs = (XiuXianXianLiRankArgs) object;
        // 初始数据不能上榜
        if (XiuXianMgr.getConfig().getInitStateId() == rankArgs.getStateId() && rankArgs.getPowerVal() <= 0L) {
            return;
        }
        if(BigInteger.valueOf(rankArgs.getStateId()).compareTo(getValue()) > 0 || !String.valueOf(rankArgs.getPowerVal()).equals(getParam())){
            setValue(BigInteger.valueOf(rankArgs.getStateId()));
            setParam(String.valueOf(rankArgs.getPowerVal()));
            rankChange();
        }
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.XiuXianXianLiRank.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.XiuXianXianLiRank.getValue(), handle);
    }

}
